<!-- 添加就诊人 -->
<template>
	<view class="add-patient-wrapper">
		<u--form labelPosition="left" :labelWidth="90" :model="formData" :rules="rules" ref="uForm">
			<u-form-item label="姓名" prop="name">
				<u--input v-model="formData.name" border="none" placeholder="请输入患者姓名"></u--input>
			</u-form-item>
			<u-form-item label="性别" prop="sex" placement="row">
				<u-radio-group v-model="formData.sex">
					<u-radio :name="'男'" label="男" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'女'" label="女"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="出生日期" prop="birthday" @click="showBirthday = true; hideKeyboard()">
				<u--input v-model="formData.birthday" disabled disabledColor="#ffffff" placeholder="请选择生日"
					border="none"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="体重(kg)" prop="weight">
				<u--input v-model="formData.weight" border="none" placeholder="请输入体重"></u--input>
			</u-form-item>
			<u-form-item label="身高(cm)" prop="height">
				<u--input v-model="formData.height" border="none" placeholder="请输入身高"></u--input>
			</u-form-item>
			<u-form-item label="婚姻状况" prop="maritalStatus">
				<u-radio-group v-model="formData.maritalStatus" placement="row">
					<u-radio :name="'已婚'" label="已婚" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'未婚'" label="未婚"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="职业" prop="occupation">
				<u--input v-model="formData.occupation" border="none" placeholder="请输入职业"></u--input>
			</u-form-item>
			<u-form-item label="血型" prop="blood">
				<u--input v-model="formData.blood" border="none" placeholder="请输入血型"></u--input>
			</u-form-item>
			<u-form-item label="患者关系" prop="relation">
				<u-radio-group v-model="formData.relation" placement="row">
					<u-radio :name="'家庭成员'" label="家庭成员" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'亲戚'" label="亲戚" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'朋友'" label="朋友" :customStyle="{marginRight:'8px'}"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="肝功能" prop="liverFunction">
				<u-radio-group v-model="formData.liverFunction" placement="row">
					<u-radio :name="'正常'" label="正常" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'异常'" label="异常"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="肾功能" prop="renalFunction">
				<u-radio-group v-model="formData.renalFunction" placement="row">
					<u-radio :name="'正常'" label="正常" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'异常'" label="异常"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="备孕情况" prop="beiyun">
				<u-radio-group v-model="formData.beiyun" placement="row">
					<u-radio :name="'无'" label="无" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'备孕中'" label="备孕中"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="高血压史" prop="gaoxueya">
				<u-radio-group v-model="formData.gaoxueya" placement="row">
					<u-radio :name="'无'" label="无" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'有'" label="有"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="糖尿病史" prop="tangniaobing">
				<u-radio-group v-model="formData.tangniaobing" placement="row">
					<u-radio :name="'无'" label="无" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'有'" label="有"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="药物过敏史" prop="yaowuguomin">
				<u-radio-group v-model="formData.yaowuguomin" placement="row">
					<u-radio :name="'无'" label="无" :customStyle="{marginRight:'8px'}"></u-radio>
					<u-radio :name="'有'" label="有"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="手机号码" prop="phone">
				<u--input v-model="formData.phone" border="none" placeholder="请输入手机号码"></u--input>
			</u-form-item>
			<u-form-item label="身份证号" prop="shenfenzheng">
				<u--input v-model="formData.shenfenzheng" border="none" placeholder="请输入身份证号"></u--input>
			</u-form-item>
			<button type="primary" @click="submit">提交</button>
		</u--form>

		<u-datetime-picker :show="showBirthday" :value="formData.birthday" mode="date" closeOnClickOverlay :minDate="30"
			@confirm="birthdayConfirm" @cancel="birthdayClose" @close="birthdayClose"></u-datetime-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					name: '黄健',
					sex: '男',
					birthday: '1990-12-04',
					weight: '50',
					height: '160',
					maritalStatus: '已婚',
					occupation: '',
					blood: 'o',
					relation: '家庭成员',
					liverFunction: '正常',
					renalFunction: '正常',
					beiyun: '无',
					gaoxueya: '无',
					tangniaobing: '无',
					yaowuguomin: '无',
					phone: '13768615462',
					shenfenzheng: '450122199292932222'
				},
				rules: {
					name: {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur']
					},
					birthday: {
						type: 'string',
						required: true,
						message: '请选择出生日期',
						trigger: ['blur']
					},
					weight: {
						type: 'string',
						required: true,
						message: '请填写体重',
						trigger: ['blur']
					},
					height: {
						type: 'string',
						required: true,
						message: '请填写身高',
						trigger: ['blur']
					},
					phone: {
						type: 'string',
						required: true,
						message: '请填写手机号码',
						trigger: ['blur']
					},
					shenfenzheng: {
						type: 'string',
						required: true,
						message: '请填写身份证号',
						trigger: ['blur']
					}
				},
				showBirthday: false
			}
		},
		onLoad(option) {
			this.$app._get('entry/wxapp/user.alluserfamily', {
				openid: wx.getStorageSync("openid")
			}, (result) => {
				console.log(result);
			})
		},
		methods: {
			birthdayClose() {
				this.showBirthday = false
				this.$refs.uForm.validateField('formData.birthday')
			},
			birthdayConfirm(e) {
				this.showBirthday = false
				this.formData.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
				this.$refs.uForm.validateField('formData.birthday')
			},
			submit() {
				this.$refs.uForm.validate().then(res => {
					uni.$u.toast('校验通过')
					this.$app._get('entry/wxapp/user.addjiaren', {
						pap_index: 0,
						sick_index: this.formData.relation,
						region: '',
						datetime: this.formData.birthday,
						names: this.formData.name,
						numcard: this.formData.shenfenzheng,
						tel: this.formData.phone,
						sex: this.formData.sex,
						openid: wx.getStorageSync("openid"),
						tizhong: this.formData.weight,
						shengao: this.formData.height,
						hunyin: this.formData.maritalStatus,
						zhiye: this.formData.occupation,
						gan_index: this.formData.liverFunction,
						shen_index: this.formData.renalFunction,
						be_index: this.formData.beiyun,
						xuex: this.formData.blood
					}, (result) => {
						console.log(result);
					})
				}).catch(errors => {

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.add-patient-wrapper {
		width: 100%;
		padding: 20px;
		box-sizing: border-box;
		background-color: #fff;
	}
</style>